<?php




class SkinMod extends ModBase{

	private $api = null;
	private static $style = 'default';
	
	
	/**
	 * 构造函数，初始化插件
	 */
	public function __construct() {
		parent::__construct();
		if(defined('N_STYLE')){
			self::$style = N_STYLE;
		}
		
		$this->api = n_api("skin");
	
		self::$style = 'tr';
	}
	
	public function header($style=''){
		if(in_array(N_TYPE,array('ajax','iframe'))){
			return '';
		}
		if(empty($style)){
			$style = 'admin';
		}
		if (defined('N_USER') && N_USER=='Y' && $style == 'admin') {
			$style = 'tr';
		}
		$filepath = N_PLUGINS . "/skin/html/header-".$style.".html";
		$this->loadhtml($filepath);

	}
	public function footer($style=''){
		if(in_array(N_TYPE,array('ajax','iframe'))){
			return '';
		}

		if(empty($style)){
			$style = 'admin';
		}

		if (defined('N_USER') && N_USER=='Y' && $style == 'admin') {
			$style = 'tr';
		}

		$filepath = N_PLUGINS . "/skin/html/footer-".$style.".html";
		$this->loadhtml($filepath);
	}

	public function save($msg='保存成功！',$time=0,$gourl=''){

		if(n_isWap()){
			$filepath = N_PLUGINS . "/skin/html/wapSave.html";
		}else{
			$filepath = N_PLUGINS . "/skin/html/save.html";
		}
		
		$rs = array("msg"=>$msg,"time"=>$time,"gourl"=>$gourl);
		$this->loadhtml($filepath,$rs);
	}

	public function pajax($tips,$gourl=''){
		$filepath = N_PLUGINS . "/skin/html/pajax.html";

		$this->loadhtml($filepath,$tips);
	}
	private function loadhtml($filepath,$data=array()){
		
		if(!file_exists($filepath)){
			throw new CException("找不到头文件:{$filepath}");
		}
		include $filepath;
	}
	

	/**
	 * 设置头部的页面信息
	 * 
	 * @param unknown_type $title
	 * @param unknown_type $keyword
	 * @param unknown_type $descript
	 */
	public function setHeader($title,$keyword,$descript){
		define("P_TITLE",$title);
		define("P_KEYWORD",$keyword);
		define("P_DESCRIPT",$descript);
	}
	
	
	
	public function table(){
		$this->_html("table");
	}
	public function box(){
		$this->_html("box");
	}
	public function paging(){
		
		$rs['paging'] = n_api("common")->paging("#",10,1000,20);
		$this->_html("paging",$rs);
	}
	public function common(){
		$this->_html("common");
	}
	public function nav($data,$a=array(),$tips=""){
		$rs['nav'] = array();
		foreach($data as $key=>$val){
			if(is_array($val)){
				$rs['nav'][] = "<a href='{$val['url']}'>{$val['text']}</a>";
			}else{
				$rs['nav'][] = $val;
			}
		}
		
		$rs['a'] = $a;
		$rs['tips'] = $tips;

		$this->_html('nav',$rs);
	}
	public function crumb(){
		n_api("common")->setCrumb("第一节");
		n_api("common")->setCrumb("第二节");
		n_api("common")->setCrumb("第三节");
		n_api("common")->setCrumb("最后一节");
		
		$this->_html("crumb");
	}
	public function form(){
		$this->_html("form");
	}


	public function pageHead($title,$tools=array()) {
		$rs['title'] = $title;
		$rs['tools'] = $tools;

		$crumbs = n_api('common')->getCrumb();

		$rs['crumbs'] = $crumbs;

		$this->_html(N_TYPE=="page"?"pageHead":"pageHeadPly",$rs);
	}



	public function elem(){
		$this->_html("elem");
	}
}